package com.yitao.cms.mapper;


import com.yitao.client.model.product.ProductInfoModelForSearch;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * Date: 2018/11/27
 *
 * @author skipper
 * @desc message es检索仓库接口
 * @see
 */

@Component
public interface ProductRepository extends ElasticsearchRepository<ProductInfoModelForSearch, Long> {

    /**
     * 保存一条资讯
     * @param productInfoModelForSearch
     * @return
     */
    ProductInfoModelForSearch save(ProductInfoModelForSearch productInfoModelForSearch);


    /**
     * 根据id查询
     * @param Id
     * @return
     */
    ProductInfoModelForSearch getById(Long Id);

    /**
     *  根据内容分词检索  按创建时间倒序
     * @param productName
     * @param pageable
     * @return
     */
    Page<ProductInfoModelForSearch> findByProductName(String productName, Pageable pageable);

    /**
     *  根据内容分词检索  按创建时间倒序
     * @param productName
     * @param pageable
     * @return
     */
    Page<ProductInfoModelForSearch> findByProductNameOrProductDescriptionOrderByCreateTimeDesc(String productName,
                                                                                               String productDescription, Pageable pageable);
    /**
     * 根据ID删除数据
     * @param id
     * @return
     */
    int deleteById(Long id);

    int deleteAllByIdIn(List<Long> ids);
}
